﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LASTTESTMVC.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            Debug.WriteLine("hello!");
            return View();
        }

        public ActionResult Index2()
        {
            EventLog[] eventLogs = EventLog.GetEventLogs();
            List<EventLog> list = new List<EventLog>();

            for (int i = 0; i < eventLogs.Length; i++)
            {
                list.Add(eventLogs[i]);
            }
            ViewBag.list = list;
            Debug.WriteLine(list[2].Entries);
            return View();
        }

        public ActionResult Index3()
        {
            EventLog[] eventLogs = EventLog.GetEventLogs();
            EventLog testlog = eventLogs[2];
            FileInfo t = new FileInfo(testlog.Log);
            string filelog_path = t.DirectoryName;
            string file_path = Server.MapPath("~/Doctor Web.evtx");
            string file_type = "application/octet-stream";
            string file_name = "Files.evtx";
            return File(file_path, file_type, file_name);
        }

        public ActionResult DownloadLogWithName(string id) //in this action we should take the request with parameter-name of the logfile
        { //(write in routeconfig?)
            string partpath = String.Concat("C:/", id); //C:/ is just an example of pysical path to file
            string file_path = String.Concat(partpath, ".evtx"); //got full path with concrete logfile name
            string file_type = "application/octet-stream"; //type of evt file
            string file_name = String.Concat(id, ".evtx"); //give the saving file name of downloading logfile
            return File(file_path, file_type, file_name); //download file
        }
    }
}
